//
//  ZZMyInfoViewController.m
//  ZuZuBao
//
//  Created by Felix on 2024/4/10.
//

#import "ZZMyInfoViewController.h"
#import "ZZMyInfoTableViewCell.h"

@interface ZZMyInfoViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) NSMutableArray * dataArray;

@end

@implementation ZZMyInfoViewController
{
    UITableView *tableView;
}

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.dataArray = [NSMutableArray arrayWithObjects:@"头像", @"昵称", @"账号", nil];
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"我的资料";
    
    [self createView];
}

-(void)createView {
    tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavBarHeight, kScreenWidth, kScreenHeight - kNavBarHeight) style:UITableViewStylePlain];
    tableView.backgroundColor = kBackColor;
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:tableView];
    [tableView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // 返回你想要的行数
    return self.dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return 90;
    }
    return 68;
}
  
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // 注册自定义cell的类，如果还没有注册过
    static NSString *cellIdentifier = @"ZZMyInfoTableViewCell";
    [tableView registerClass:[ZZMyInfoTableViewCell class] forCellReuseIdentifier:cellIdentifier];
      
    // 从队列中复用cell或创建新的cell
    ZZMyInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    // 设置cell的数据
    [cell setCellData:self.dataArray[indexPath.row]];
    if (indexPath.row == 0) {
        cell.contLabel.hidden = YES;
        cell.imgView.hidden = NO;
        [cell.imgView sd_setImageWithURL:[NSURL URLWithString:kHeadImg]];
    } else if (indexPath.row == 1) {
        cell.contLabel.hidden = NO;
        cell.imgView.hidden = YES;
        cell.contLabel.text = kNickName;
    } else if (indexPath.row == 2) {
        cell.contLabel.hidden = NO;
        cell.imgView.hidden = YES;
        if (kPhone.length > 7) {
            cell.contLabel.text = [kPhone stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
        } else {
            cell.contLabel.text = kPhone;
        }
    }
    
    return cell;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
